<template>
  <div>
    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
      <div class="widget am-cf">
        <div class="widget-head am-cf">
          <div class="widget-title am-fl">学生成绩</div>
        </div>
        <div class="widget-body  am-fr">

          <div class="am-u-sm-12 am-form ">
            <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
              <div class="am-form-group">
                <input type="text" name="title" v-model="query.studentName" placeholder="请输入学生姓名"/>
              </div>
            </div>

            <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
              <div class="am-form-group">
                <input type="text" name="title" v-model="query.studentPhoneNo" placeholder="请输入手机号"/>
              </div>
            </div>

            <div class="am-u-sm-12 am-u-md-12 am-u-lg-3 am-u-end">
              <div class="am-form-group">
                <button type="button" class="am-btn am-btn-default am-btn-success"
                        @click="search" ><span class="am-icon-search"></span>查询
                </button>
                <button v-if="hasPermission('export')" type="button" class="am-btn am-btn-default am-btn-success"
                        @click="handleExport"><span
                  class="am-icon-plus"></span>导出
                </button>
              </div>
            </div>

          </div>

          <div class="am-u-sm-12">
            <el-table
              :data="tableData"
              border
              stripe
              style="min-width: 100%">
              <el-table-column
                prop="studentName"
                label="姓名"
                min-width="100">
              </el-table-column>
              <el-table-column
                prop="studentPhoneNo"
                label="手机号"
                min-width="100">
              </el-table-column>
              <el-table-column
                prop="gradeName"
                label="年级"
                min-width="100">
              </el-table-column>
              <el-table-column
                prop="subjectName"
                label="科目"
                min-width="100">
              </el-table-column>
              <el-table-column
                prop="score"
                label="中考单科分数"
                min-width="100">
                <template scope="scope">
                  <div v-if="scope.row.scoreType === '1'">
                    {{scope.row.score | formatNumber(0)}}
                  </div>
                  <div v-else>
                    -
                  </div>
                </template>
              </el-table-column>
              <el-table-column
                prop="score"
                label="学业诊断名次"
                min-width="100">
                <template scope="scope">
                  <div v-if="scope.row.scoreType === '2'">
                    {{scope.row.score | formatNumber(0)}}
                  </div>
                  <div v-else>
                    -
                  </div>
                </template>
              </el-table-column>
              <el-table-column
                v-if="!measurementId"
                label="录入时间"
                min-width="150">
                <template scope="scope">
                  <div>
                    {{scope.row.createTime | formatTime}}
                  </div>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div class="am-u-lg-12 am-cf">
            <div class="am-fr">
              <pagination v-bind:total="total" v-bind:pageNo="pageNo" v-bind:pageSize="pageSize"
                          @paging="loadTableData"/>
            </div>
          </div>
        </div>
      </div>
    </div>

  </div>
</template>

<script>

  import Pagination from '../base/Pagination'
  import io from '../../lib/io/index'

  export default{
    data: function () {
      return {
        multipleSelection: [],
        examPaperIds: [],
        measurementId: '',
        tableData: [],
        total: 0,
        pageSize: 10,
        pageNo: 1,
        query: {
          studentName: '',
          studentPhoneNo: '',
        },
        periods: [],
        searchConfig: {}
      }
    },
    components: {
      Pagination
    },
    mounted: function () {
      $(window).smoothScroll()
    },
    created: function () {
      this.loadTableData(1)
    },
    methods: {
      handleDelete(examPaperId) {
        var _this = this
        _this.$confirm('你确定要删除？',
          function () {
            io.post(io.delExamPaper, {
              examPaperId: examPaperId,
            }, function (ret) {
              if (ret.success) {
                _this.$toast('删除成功！')
                _this.loadTableData()
              } else {
                _this.$alert(ret.desc)
              }
            })
          });
      },
      handleLooking(examPaperId) {
        this.$refs.paperDetail.examPaperId = examPaperId
        this.$refs.paperDetail.show()
      },
      search:function(){
        this.loadTableData(1)
      },
      handleExport:function(){
        var _this = this
        io.downloadFile(io.exportExternalMeasureScoreList, {
          studentName: _this.query.studentName,
          studentPhoneNo: _this.query.studentPhoneNo,
        }, function (ret) {
          if (ret.success) {
          } else {
            _this.$alert(ret.desc)
          }
        })
      },
      loadTableData: function (pageNo) {
        var _this = this
        _this.pageNo = pageNo || _this.pageNo || 1
        io.post(io.externalMeasureScoreList, {
          studentName: _this.query.studentName,
          studentPhoneNo: _this.query.studentPhoneNo,
          pageNo: _this.pageNo,
          pageSize: _this.pageSize,
        }, function (ret) {
          if (ret.success) {
            _this.total = ret.data.total
            _this.tableData = ret.data.list
          } else {
            _this.$alert(ret.desc)
          }
        })
      },
    }
  }
</script>
<style scoped lang="less">
  .red {
    color: red;
  }
  .content-tooltip {
    unicode-bidi: embed;
    white-space: pre;
    font-size: 14px;
    line-height: 1.5;
  }
</style>
